package com.kewu.common.global;

import com.kewu.common.enums.ErrorCodeEnum;
import com.kewu.common.enums.IErrorEnum;
import lombok.Getter;

@Getter
public class CustomException extends RuntimeException {

    private String errCode;
    private String errMsg;

    public CustomException(String errCode, String errMsg) {
        super(String.format("errCode:[%s], errMsg:=> %s", errCode, errMsg));
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public CustomException(String errCode, String errMsg, Throwable throwable) {
        super(throwable);
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public CustomException(IErrorEnum errorCode) {
        super(String.format("errCode:[%s], errMsg:=> %s", errorCode.getErrCode(), errorCode.getErrMsg()));
        this.errCode = errorCode.getErrCode();
        this.errMsg = errorCode.getErrMsg();
    }


    public CustomException() {

    }

    public ResponseData resp() {
        return ResponseData.error(this.getErrCode(), this.getErrMsg());
    }

}
